<!DOCTYPE html>
<html  lang="zh">
<head>
    <meta charset="utf-8" />

<meta name="generator" content="Hexo 3.9.0" />

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

<title>浅析Java中的反射机制 - Ayang818&#39;s blog</title>


    <meta name="description" content="作用反射机制属于Java中的常用的高级机制之一，他的功能非常强大，反射机制可以用来  在运行时分析类的能力 在运行时查看对象，如编写一个toString方法供所有类使用 实现通用的数组操作代码 利用Method对象，这个对象很像C++中的函数指针">
<meta name="keywords" content="Java,反射">
<meta property="og:type" content="article">
<meta property="og:title" content="浅析Java中的反射机制">
<meta property="og:url" content="https://ayang818.gitee.io/blog/浅析Java中的反射机制/index.html">
<meta property="og:site_name" content="Ayang818&#39;s blog">
<meta property="og:description" content="作用反射机制属于Java中的常用的高级机制之一，他的功能非常强大，反射机制可以用来  在运行时分析类的能力 在运行时查看对象，如编写一个toString方法供所有类使用 实现通用的数组操作代码 利用Method对象，这个对象很像C++中的函数指针">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://ayang818.gitee.io/blog/images/og_image.png">
<meta property="og:updated_time" content="2020-04-12T17:32:25.846Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="浅析Java中的反射机制">
<meta name="twitter:description" content="作用反射机制属于Java中的常用的高级机制之一，他的功能非常强大，反射机制可以用来  在运行时分析类的能力 在运行时查看对象，如编写一个toString方法供所有类使用 实现通用的数组操作代码 利用Method对象，这个对象很像C++中的函数指针">
<meta name="twitter:image" content="https://ayang818.gitee.io/blog/images/og_image.png">







<link rel="icon" href="https://upload-serve.oss-cn-beijing.aliyuncs.com/avatar/avatar.jpg">


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/androidstudio.css">


    
    
<style>body>.footer,body>.navbar,body>.section{opacity:0}</style>

    
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css">

    
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css">

    
    
    
    
<link rel="stylesheet" href="/blog/css/back-to-top.css">

    
    
    
    
    
    
    
    <link rel="stylesheet" href="/blog/css/progressbar.css">
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
    
    
    


<link rel="stylesheet" href="/blog/css/style.css">
</head>
<body class="is-3-column">
    <nav class="navbar navbar-main">
    <div class="container">
        <div class="navbar-brand is-flex-center">
            <a class="navbar-item navbar-logo" href="/blog/">
            
                <img src="https://upload-serve.oss-cn-beijing.aliyuncs.com/avatar/avatar.jpg" alt="浅析Java中的反射机制" height="28">
            
            </a>
        </div>
        <div class="navbar-menu">
            
            <div class="navbar-start">
                
                <a class="navbar-item"
                href="/blog/">主页</a>
                
                <a class="navbar-item"
                href="/blog/archives">归档</a>
                
                <a class="navbar-item"
                href="/blog/tags">分类</a>
                
                <a class="navbar-item"
                href="/blog/about">关于</a>
                
                <a class="navbar-item"
                href="https://github.com/ayang818">Github</a>
                
            </div>
            
            <div class="navbar-end">
                
                    
                    <a class="navbar-item" target="_blank" rel="noopener" title="Github" href="https://github.com/ayang818">
                        
                        <i class="fab fa-github"></i>
                        
                    </a>
                    
                
                
                
                <a class="navbar-item search" title="搜索" href="javascript:;">
                    <i class="fas fa-search"></i>
                </a>
                
            </div>
        </div>
    </div>
</nav>
    
    <section class="section">
        <div class="container">
            <div class="columns">
                <div class="column is-8-tablet is-8-desktop is-9-widescreen has-order-2 column-main">
<div class="card">
    
    <div class="card-content article ">
        
        <div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto">
            <div class="level-left">
                <time class="level-item has-text-grey" datetime="2019-08-27T12:27:05.000Z">2019-08-27</time>
                
                
                <span class="level-item has-text-grey">
                    
                    
                    12 minutes 读完 (大约 1850 个字)
                </span>
                
                
            </div>
        </div>
        
        <h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal">
            
                浅析Java中的反射机制
            
        </h1>
        <div class="content">
            <h2 id="作用"><a href="#作用" class="headerlink" title="作用"></a>作用</h2><p>反射机制属于Java中的常用的高级机制之一，他的功能非常强大，反射机制可以用来</p>
<ul>
<li>在运行时分析类的能力</li>
<li>在运行时查看对象，如编写一个toString方法供所有类使用</li>
<li>实现通用的数组操作代码</li>
<li>利用Method对象，这个对象很像C++中的函数指针</li>
</ul>
<a id="more"></a>
<h2 id="Class类"><a href="#Class类" class="headerlink" title="Class类"></a>Class类</h2><p>在运行期间，Java始终为所有对象维护一个被称为<strong>运行时</strong>的类型标识，这个信息跟踪着每个对象所属的类。虚拟机利用运行时类型信息选择相应的方法执行。然而我们可以使用专门的Java类访问这些信息。保存这些信息的类就被称为Class。关于如何获得这个Class对象有如下方法</p>
<h3 id="getClass方法和它的getName方法"><a href="#getClass方法和它的getName方法" class="headerlink" title="getClass方法和它的getName方法"></a>getClass方法和它的getName方法</h3><p>Object类中的getClass方法就会返回一个Class类型的实例</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        ArrayList&lt;String&gt; strings = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        System.out.println(strings.getClass());</span><br><span class="line">        System.out.println(strings.getClass().getName());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; <span class="class"><span class="keyword">class</span> <span class="title">java</span>.<span class="title">util</span>.<span class="title">ArrayList</span></span></span><br><span class="line"><span class="class">&gt;&gt;&gt; <span class="title">java</span>.<span class="title">util</span>.<span class="title">ArrayList</span></span></span><br></pre></td></tr></table></figure>

<h3 id="静态方法forName"><a href="#静态方法forName" class="headerlink" title="静态方法forName"></a>静态方法forName</h3><p>Class类的静态方法forName可以获得对应的Class对象</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String string = <span class="string">"java.util.Random"</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Class&lt;?&gt; aClass = Class.forName(string);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="直接使用-class"><a href="#直接使用-class" class="headerlink" title="直接使用.class"></a>直接使用.class</h3><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        System.out.println(String.class.getName());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; java.lang.String</span><br></pre></td></tr></table></figure>

<h3 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h3><p>其实一个Class对象实际上表示的是一个类型，而这个类型未必是一个类，例如int不是类，但是int.class是一个Class类型的对象</p>
<h3 id="实现类对象的比较"><a href="#实现类对象的比较" class="headerlink" title="==实现类对象的比较"></a>==实现类对象的比较</h3><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String string = <span class="string">"hello"</span>;</span><br><span class="line">        System.out.println(string.getClass() == String.class);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="使用newInstance-动态创建一个类的实例"><a href="#使用newInstance-动态创建一个类的实例" class="headerlink" title="使用newInstance()动态创建一个类的实例"></a>使用newInstance()动态创建一个类的实例</h3><ul>
<li>使用Class中的newInstance创建一个无参实例</li>
<li>使用java.lang.reflect.Constructor中的newInstance创建一个有参实例<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String string = <span class="string">"java.lang.String"</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Object object = Class.forName(string).newInstance();</span><br><span class="line">            <span class="keyword">if</span> (object.getClass() == String.class) &#123;</span><br><span class="line">                String string2 = (String) object;</span><br><span class="line">                System.out.println(string2.isEmpty());</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (InstantiationException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IllegalAccessException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; <span class="keyword">true</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="使用反射分析类的能力"><a href="#使用反射分析类的能力" class="headerlink" title="使用反射分析类的能力"></a>使用反射分析类的能力</h2><p>反射机制最重要的内容就是，检查类的结构，在java.lang.reflect包下，有三个类，Field,Method,Constructor，可以用来查看类的结构，如下一段程序使用这个特性完成了打印一个类的Field，Method,Constructor的功能</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> java.lang.reflect.*;</span><br><span class="line"><span class="keyword">import</span> java.util.Scanner;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String name;</span><br><span class="line">        <span class="keyword">if</span> (args.length != <span class="number">0</span>) &#123;</span><br><span class="line">            name = args[<span class="number">0</span>];</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            Scanner scanner = <span class="keyword">new</span> Scanner(System.in);</span><br><span class="line">            name = scanner.nextLine();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Class&lt;?&gt; aClass = Class.forName(name);</span><br><span class="line">            Class&lt;?&gt; superclass = aClass.getSuperclass();</span><br><span class="line">            String string = Modifier.toString(aClass.getModifiers());</span><br><span class="line">            <span class="keyword">if</span>(string.length() &gt; <span class="number">0</span>) System.out.print(string+<span class="string">" "</span>);</span><br><span class="line">            System.out.print(<span class="string">"class "</span>+ name);</span><br><span class="line">            <span class="keyword">if</span> (superclass != <span class="keyword">null</span> &amp;&amp; superclass != Object.class) System.out.println(<span class="string">" extends "</span>+superclass.getName());</span><br><span class="line">            System.out.print(<span class="string">"\n&#123;\n"</span>);</span><br><span class="line">            printConstructors(aClass);</span><br><span class="line">            System.out.println();</span><br><span class="line">            printMethod(aClass);</span><br><span class="line">            System.out.println();</span><br><span class="line">            printField(aClass);</span><br><span class="line">            System.out.println();</span><br><span class="line">            System.out.println(<span class="string">"&#125;"</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">printField</span><span class="params">(Class&lt;?&gt; aClass)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// getDeclareField获得这个类的所有域，getField获得这个类和他的超类的所有域</span></span><br><span class="line">        Field[] fields = aClass.getDeclaredFields();</span><br><span class="line">        <span class="keyword">for</span> (Field field : fields) &#123;</span><br><span class="line">            String string = Modifier.toString(field.getModifiers());</span><br><span class="line">            System.out.print(string + <span class="string">" "</span>);</span><br><span class="line">            System.out.print(field.getType());</span><br><span class="line">            System.out.print(<span class="string">" "</span>+field.getName());</span><br><span class="line">            System.out.println();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">printMethod</span><span class="params">(Class&lt;?&gt; aClass)</span> </span>&#123;</span><br><span class="line">        Method[] methods = aClass.getDeclaredMethods();</span><br><span class="line">        <span class="keyword">for</span> (Method method : methods) &#123;</span><br><span class="line">            String string = Modifier.toString(method.getModifiers());</span><br><span class="line">            System.out.print(string + <span class="string">" "</span>);</span><br><span class="line">            System.out.print(method.getReturnType()+ <span class="string">" "</span>);</span><br><span class="line">            System.out.print(method.getName());</span><br><span class="line">            System.out.print(<span class="string">"("</span>);</span><br><span class="line">            Class&lt;?&gt;[] parameterTypes = method.getParameterTypes();</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; parameterTypes.length; i++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (i &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                    System.out.print(<span class="string">","</span>);</span><br><span class="line">                &#125;</span><br><span class="line">                System.out.print(parameterTypes[i].getName());</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(<span class="string">");"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">printConstructors</span><span class="params">(Class c)</span> </span>&#123;</span><br><span class="line">        Constructor[] declaredConstructors = c.getDeclaredConstructors();</span><br><span class="line">        <span class="keyword">for</span> (Constructor declaredConstructor : declaredConstructors) &#123;</span><br><span class="line">            String name = c.getName();</span><br><span class="line">            System.out.println(<span class="string">" "</span>);</span><br><span class="line">            String string = Modifier.toString(c.getModifiers());</span><br><span class="line">            <span class="keyword">if</span>(string.length() &gt; <span class="number">0</span>) System.out.print(string+<span class="string">" "</span>);</span><br><span class="line">            System.out.print(name + <span class="string">"("</span>);</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 打印参数类型</span></span><br><span class="line">            Class[] parameterTypes = declaredConstructor.getParameterTypes();</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; parameterTypes.length; i++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (i&gt;<span class="number">0</span>) &#123;</span><br><span class="line">                    System.out.print(<span class="string">" ,"</span>);</span><br><span class="line">                &#125;</span><br><span class="line">                System.out.print(parameterTypes[i].getName());</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.print(<span class="string">");"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="在运行时使用反射分析对象"><a href="#在运行时使用反射分析对象" class="headerlink" title="在运行时使用反射分析对象"></a>在运行时使用反射分析对象</h2><p>上面的代码主要用于这个类还没有运行的时候对于类的分析，下面就是使用反射对一个已经运行的实例的分析与修改。下面的代码对一个Employee实例，进行了修改</p>
<ul>
<li>getDeclaredFields获取域</li>
<li>使用setAccessible将其设置为true,否则当遇到Modifier为private的属性，将抛出IllegalAccessException</li>
<li>使用Field.get查看某个实例对应域的值</li>
<li>使用field.set(object, value)</li>
<li>关于getComponentType,如果是Array类型,他会返回数组中的内容类型，否则会返回null</li>
<li>你可以通过这种形式加上递归调用实现一个通用的toString方法<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> java.lang.reflect.Field;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Employee ayang919 = <span class="keyword">new</span> Employee(<span class="string">"ayang919"</span>, <span class="string">"homework"</span>);</span><br><span class="line">        Class&lt;? extends Employee&gt; aClass = ayang919.getClass();</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Field[] fields = aClass.getDeclaredFields();</span><br><span class="line">            <span class="keyword">for</span> (Field field : fields) &#123;</span><br><span class="line">                field.setAccessible(<span class="keyword">true</span>);</span><br><span class="line">                System.out.println(field.get(ayang919));</span><br><span class="line">                field.set(ayang919, <span class="string">"new work"</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println();</span><br><span class="line">            System.out.println(ayang919.task);</span><br><span class="line">            System.out.println(ayang919.getName());</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IllegalAccessException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Employee</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">public</span> String task;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">Employee</span><span class="params">(String name, String task)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.name = name;</span><br><span class="line">        <span class="keyword">this</span>.task = task;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getName</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> name;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> java.lang.reflect.AccessibleObject;</span><br><span class="line"><span class="keyword">import</span> java.lang.reflect.Array;</span><br><span class="line"><span class="keyword">import</span> java.lang.reflect.Field;</span><br><span class="line"><span class="keyword">import</span> java.lang.reflect.Modifier;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> rambo.pan</span></span><br><span class="line"><span class="comment"> * 2016年10月10日</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ObjectAnalyzer</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> String NULL_STRING = <span class="string">"null"</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> String VISITED_STRING = <span class="string">"..."</span>;</span><br><span class="line">    <span class="comment">//该数组用来记录已解析过的对象类型</span></span><br><span class="line">    <span class="keyword">private</span> List&lt;Object&gt; visited = <span class="keyword">new</span> ArrayList&lt;Object&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 递归方法，object是个数组，则遍历其元素，递归调用该方法；否则是个类实例，则遍历其所有字段</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> obj</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">toString</span><span class="params">(Object obj)</span></span>&#123;</span><br><span class="line">        <span class="comment">//如果对象为空，则返回null</span></span><br><span class="line">        <span class="keyword">if</span> (obj == <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> NULL_STRING;</span><br><span class="line">        &#125;</span><br><span class="line">      <span class="comment">//如果对象已被处理过，则返回，针对于 A、B对象相互组合的情况，否则会循环递归，导致StackOverFlow</span></span><br><span class="line">        <span class="keyword">if</span> (visited.contains(obj)) &#123;</span><br><span class="line">            <span class="keyword">return</span> VISITED_STRING;</span><br><span class="line">        &#125;</span><br><span class="line">        visited.add(obj);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取对象的Class实例，同一个类的对象，共有一个相应的Class实例，在类被加载到虚拟机时就存储在方法区中了</span></span><br><span class="line">        Class&lt;?&gt; cl = obj.getClass();</span><br><span class="line">        <span class="comment">//如果对象正好是String对象，则强转后直接返回</span></span><br><span class="line">        <span class="keyword">if</span> (cl == String.class) &#123;</span><br><span class="line">            <span class="keyword">return</span> (String)obj;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//如果object是个数组，则遍历其元素，对元素进行toString(Object)递归调用</span></span><br><span class="line">        <span class="keyword">if</span> (cl.isArray()) &#123;</span><br><span class="line">            <span class="comment">//获取数组的元素类型</span></span><br><span class="line">            String r = cl.getComponentType() + <span class="string">"[]&#123;"</span>;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; Array.getLength(obj); i++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (i &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                    r += <span class="string">","</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//获取指定下标的数组元素</span></span><br><span class="line">                Object val = Array.get(obj, i);</span><br><span class="line">                <span class="comment">//如果元素是原始/基本类型(Java共8种基本类型),则直接输出</span></span><br><span class="line">                <span class="keyword">if</span> (cl.getComponentType().isPrimitive()) &#123;</span><br><span class="line">                    r += val;</span><br><span class="line">                &#125;<span class="keyword">else</span> &#123;<span class="comment">//否则递归调用，直到其为原始类型</span></span><br><span class="line">                    r += toString(val);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//对数组元素遍历完成，返回。</span></span><br><span class="line">            <span class="keyword">return</span> r + <span class="string">"&#125;"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//object不是数组类型，首先获取其类型Name</span></span><br><span class="line">        String r = cl.getName();</span><br><span class="line">        <span class="comment">//遍历object的所有字段，然后获取字段的Name和Value，之后再遍历其父类，直到遍历到父类为Object</span></span><br><span class="line">        <span class="keyword">do</span>&#123;</span><br><span class="line">            r += <span class="string">"["</span>;</span><br><span class="line">            <span class="comment">//获取object的所有字段，无论访问限制符是public还是private，但不包括其从父类继承来的字段</span></span><br><span class="line">            Field[] fields = cl.getDeclaredFields();</span><br><span class="line">            <span class="comment">//设置字段的访问权限为可访问</span></span><br><span class="line">            AccessibleObject.setAccessible(fields, <span class="keyword">true</span>);</span><br><span class="line">            <span class="keyword">for</span> (Field field : fields) &#123;</span><br><span class="line">                <span class="comment">//忽略static属性</span></span><br><span class="line">                <span class="keyword">if</span> (Modifier.isStatic(field.getModifiers())) &#123;</span><br><span class="line">                    <span class="keyword">continue</span>;</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">                <span class="keyword">if</span> (!r.endsWith(<span class="string">"["</span>)) &#123;</span><br><span class="line">                    r += <span class="string">","</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                r += field.getName() + <span class="string">"="</span>;</span><br><span class="line">                <span class="keyword">try</span>&#123;</span><br><span class="line">                    <span class="comment">//获取字段类型和字段的值</span></span><br><span class="line">                    Class&lt;?&gt; t = field.getType();</span><br><span class="line">                    Object val = field.get(obj);</span><br><span class="line">                    <span class="comment">//如果字段类型是原始类型，则直接输出；否则递归调用toString(Object)</span></span><br><span class="line">                    <span class="keyword">if</span> (t.isPrimitive()) &#123;</span><br><span class="line">                        r += val;</span><br><span class="line">                    &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">                        r += toString(val);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;<span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">                    e.printStackTrace();</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//一个类型的字段遍历结束</span></span><br><span class="line">            r += <span class="string">"]"</span>;</span><br><span class="line">            <span class="comment">//获取该类型的父类Class实例，然后继续该循环</span></span><br><span class="line">            cl = cl.getSuperclass();</span><br><span class="line">        &#125;<span class="keyword">while</span>(cl != <span class="keyword">null</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//类型遍历完成，返回object的字符串结果</span></span><br><span class="line">        <span class="keyword">return</span> r;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


        </div>
        
        <hr style="height:1px;margin:1rem 0"/>
        <div class="level is-size-7 is-uppercase">
            <div class="level-start">
                <div class="level-item">
                    <i class="fas fa-tags has-text-grey"></i>&nbsp;
                    <a class="has-link-grey -link" href="/blog/tags/Java/">Java</a>,&nbsp;<a class="has-link-grey -link" href="/blog/tags/反射/">反射</a>
                </div>
            </div>
        </div>
        
        
        
    </div>
</div>



<div class="card">
    <div class="card-content">
        <h3 class="menu-label has-text-centered">喜欢这篇文章？打赏一下作者吧</h3>
        <div class="buttons is-centered">
            
                
<a class="button is-info donate">
    <span class="icon is-small">
        <i class="fab fa-alipay"></i>
    </span>
    <span>支付宝</span>
    <div class="qrcode"><img src="https://computernetworking.oss-cn-hongkong.aliyuncs.com/temppic/alipay.jpg" alt="支付宝"></div>
</a>

                
        </div>
    </div>
</div>



<div class="card card-transparent">
    <div class="level post-navigation is-flex-wrap is-mobile">
        
        <div class="level-start">
            <a class="level level-item has-link-grey  article-nav-prev" href="/blog/mysql事务初探/">
                <i class="level-item fas fa-chevron-left"></i>
                <span class="level-item">mysql事务初探</span>
            </a>
        </div>
        
        
        <div class="level-end">
            <a class="level level-item has-link-grey  article-nav-next" href="/blog/使用枚举来定制通用的异常处理机制/">
                <span class="level-item">使用枚举来定制通用的异常处理机制</span>
                <i class="level-item fas fa-chevron-right"></i>
            </a>
        </div>
        
    </div>
</div>



<div class="card">
    <div class="card-content">
        <h3 class="title is-5 has-text-weight-normal">评论</h3>
        
<div id="comment-container"></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.4.1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1.4.1/dist/gitalk.min.js"></script>
<script>
    var gitalk = new Gitalk({
        clientID: '2df080a3f11a34fc4f0d',
        clientSecret: '3c6fefb8587a575f94ca5a00cdf6ad9e41ad0c0c',
        id: 'af30ec522ed38922e1784c0f46b875a0',
        repo: 'comment-repo',
        owner: 'ayang818',
        admin: "ayang818",
        createIssueManually: false,
        distractionFreeMode: false
    })
    gitalk.render('comment-container')
</script>

    </div>
</div>
</div>
                




<div class="column is-4-tablet is-4-desktop is-3-widescreen  has-order-1 column-left ">
    
        
<div class="card widget">
    <div class="card-content">
        <nav class="level">
            <div class="level-item has-text-centered" style="flex-shrink: 1">
                <div>
                    
                    <figure class="image is-128x128 has-mb-6">
                        <img class="" src="https://upload-serve.oss-cn-beijing.aliyuncs.com/avatar/avatar.jpg" alt="Ayang818 (杨丰畅)">
                    </figure>
                    
                    <p class="is-size-4 is-block">
                        Ayang818 (杨丰畅)
                    </p>
                    
                    
                    
                    <p class="is-size-6 is-flex is-flex-center has-text-grey">
                        <i class="fas fa-map-marker-alt has-mr-7"></i>
                        <span>中国，杭州</span>
                    </p>
                    
                </div>
            </div>
        </nav>
        <nav class="level is-mobile">
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        文章
                    </p>
                    <a href="/blog/archives">
                        <p class="title has-text-weight-normal">
                            46
                        </p>
                    </a>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        分类
                    </p>
                    <a href="/blog/categories">
                        <p class="title has-text-weight-normal">
                            0
                        </p>
                    </a>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        标签
                    </p>
                    <a href="/blog/tags">
                        <p class="title has-text-weight-normal">
                            31
                        </p>
                    </a>
                </div>
            </div>
        </nav>
        
        <div class="level">
            <a class="level-item button is-link is-rounded" href="https://github.com/ayang818" target="_blank" rel="noopener">
                关注我</a>
        </div>
        
        
        
        <div class="level is-mobile">
            
            <a class="level-item button is-white is-marginless" target="_blank" rel="noopener"
                title="Github" href="https://github.com/ayang818">
                
                <i class="fab fa-github"></i>
                
            </a>
            
            <a class="level-item button is-white is-marginless" target="_blank" rel="noopener"
                title="RSS" href="/blog/">
                
                <i class="fas fa-rss"></i>
                
            </a>
            
        </div>
        
    </div>
</div>
    
        
    
        <div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            链接
        </h3>
        <ul class="menu-list">
        
            <li>
                <a class="level is-mobile" href="https://blog.csdn.net/syh0313" target="_blank" rel="noopener">
                    <span class="level-left">
                        <span class="level-item">syh0313</span>
                    </span>
                    <span class="level-right">
                        <span class="level-item tag">blog.csdn.net</span>
                    </span>
                </a>
            </li>
        
            <li>
                <a class="level is-mobile" href="https://wzyxv1n.top/" target="_blank" rel="noopener">
                    <span class="level-left">
                        <span class="level-item">wenzhuan</span>
                    </span>
                    <span class="level-right">
                        <span class="level-item tag">wzyxv1n.top</span>
                    </span>
                </a>
            </li>
        
            <li>
                <a class="level is-mobile" href="https://blog.csdn.net/weixin_43434223" target="_blank" rel="noopener">
                    <span class="level-left">
                        <span class="level-item">旧博客</span>
                    </span>
                    <span class="level-right">
                        <span class="level-item tag">blog.csdn.net</span>
                    </span>
                </a>
            </li>
        
        </ul>
        </div>
    </div>
</div>

    
        <div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            标签云
        </h3>
        <a href="/blog/tags/DevOps/" style="font-size: 12.5px;">DevOps</a> <a href="/blog/tags/Git/" style="font-size: 10px;">Git</a> <a href="/blog/tags/IDEA/" style="font-size: 10px;">IDEA</a> <a href="/blog/tags/Java/" style="font-size: 20px;">Java</a> <a href="/blog/tags/JavaWeb/" style="font-size: 10px;">JavaWeb</a> <a href="/blog/tags/Kotlin/" style="font-size: 10px;">Kotlin</a> <a href="/blog/tags/Kugga/" style="font-size: 10px;">Kugga</a> <a href="/blog/tags/Vue/" style="font-size: 10px;">Vue</a> <a href="/blog/tags/express/" style="font-size: 10px;">express</a> <a href="/blog/tags/js/" style="font-size: 12.5px;">js</a> <a href="/blog/tags/maven/" style="font-size: 10px;">maven</a> <a href="/blog/tags/mybatis/" style="font-size: 10px;">mybatis</a> <a href="/blog/tags/mysql/" style="font-size: 10px;">mysql</a> <a href="/blog/tags/python/" style="font-size: 10px;">python</a> <a href="/blog/tags/分布式理论/" style="font-size: 12.5px;">分布式理论</a> <a href="/blog/tags/前后端分离/" style="font-size: 15px;">前后端分离</a> <a href="/blog/tags/反射/" style="font-size: 10px;">反射</a> <a href="/blog/tags/并发编程/" style="font-size: 17.5px;">并发编程</a> <a href="/blog/tags/微服务/" style="font-size: 10px;">微服务</a> <a href="/blog/tags/性能挑战赛/" style="font-size: 10px;">性能挑战赛</a> <a href="/blog/tags/日常技能/" style="font-size: 10px;">日常技能</a> <a href="/blog/tags/源码/" style="font-size: 10px;">源码</a> <a href="/blog/tags/算法/" style="font-size: 10px;">算法</a> <a href="/blog/tags/算法与数据结构/" style="font-size: 10px;">算法与数据结构</a> <a href="/blog/tags/老代码/" style="font-size: 10px;">老代码</a> <a href="/blog/tags/自嗨/" style="font-size: 10px;">自嗨</a> <a href="/blog/tags/设计模式/" style="font-size: 17.5px;">设计模式</a> <a href="/blog/tags/转载/" style="font-size: 10px;">转载</a> <a href="/blog/tags/部门教程/" style="font-size: 12.5px;">部门教程</a> <a href="/blog/tags/阶段总结/" style="font-size: 10px;">阶段总结</a> <a href="/blog/tags/随笔/" style="font-size: 15px;">随笔</a>
    </div>
</div>
    
    
        <div class="column-right-shadow  ">
        
            <div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            最新文章
        </h3>
        
        <article class="media">
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-02T05:10:49.000Z">2020-05-02</time></div>
                    <a href="/blog/第一届云原生编程挑战赛-分布式统计和过滤的链路追踪/" class="title has-link-black-ter is-size-6 has-text-weight-normal">第一届云原生编程挑战赛参赛小结</a>
                    <p class="is-size-7 is-uppercase">
                        
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-04-24T04:18:07.000Z">2020-04-24</time></div>
                    <a href="/blog/DevOps-使用Azure-pipeline为你的应用构建CI-CD流水线/" class="title has-link-black-ter is-size-6 has-text-weight-normal">[DevOps] 使用Azure pipeline + Github为你的应用构建CI/CD流水线</a>
                    <p class="is-size-7 is-uppercase">
                        
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-04-12T14:59:58.000Z">2020-04-12</time></div>
                    <a href="/blog/DevOps-如何写一个可快速构建镜像的Dockerfile脚本/" class="title has-link-black-ter is-size-6 has-text-weight-normal">[DevOps] 如何写一个可快速构建镜像的Dockerfile脚本</a>
                    <p class="is-size-7 is-uppercase">
                        
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-03-01T14:43:07.000Z">2020-03-01</time></div>
                    <a href="/blog/java-instrument/" class="title has-link-black-ter is-size-6 has-text-weight-normal">浅析Java强大的动态Instrumention能力</a>
                    <p class="is-size-7 is-uppercase">
                        
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-02-14T08:32:18.000Z">2020-02-14</time></div>
                    <a href="/blog/常用的一些算法板子-持续更新/" class="title has-link-black-ter is-size-6 has-text-weight-normal">常用的一些算法板子(持续更新)</a>
                    <p class="is-size-7 is-uppercase">
                        
                    </p>
                </div>
            </div>
        </article>
        
    </div>
</div>
        
            <div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            归档
        </h3>
        <ul class="menu-list">
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2020/05/">
                <span class="level-start">
                    <span class="level-item">May 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2020/04/">
                <span class="level-start">
                    <span class="level-item">April 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2020/03/">
                <span class="level-start">
                    <span class="level-item">March 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2020/02/">
                <span class="level-start">
                    <span class="level-item">February 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2020/01/">
                <span class="level-start">
                    <span class="level-item">January 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/12/">
                <span class="level-start">
                    <span class="level-item">December 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">3</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/11/">
                <span class="level-start">
                    <span class="level-item">November 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/10/">
                <span class="level-start">
                    <span class="level-item">October 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">8</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/09/">
                <span class="level-start">
                    <span class="level-item">September 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">9</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/08/">
                <span class="level-start">
                    <span class="level-item">August 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">7</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/07/">
                <span class="level-start">
                    <span class="level-item">July 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">7</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/06/">
                <span class="level-start">
                    <span class="level-item">June 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/blog/archives/2019/03/">
                <span class="level-start">
                    <span class="level-item">March 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        </ul>
        </div>
    </div>
</div>
        
        </div>
    
</div>

                
            </div>
        </div>
    </section>
    <footer class="footer">
    <div class="container">
        <div class="level">
            <div class="level-start has-text-centered-mobile">
                <a class="footer-logo is-block has-mb-6" href="/blog/">
                
                    <img src="https://upload-serve.oss-cn-beijing.aliyuncs.com/avatar/avatar.jpg" alt="浅析Java中的反射机制" height="28">
                
                </a>
                <p class="is-size-7">
                &copy; 2020 ayang818&nbsp;
                Powered by <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a> & <a
                        href="https://github.com/ppoffice/hexo-theme-icarus" target="_blank" rel="noopener">Icarus</a>
                
                </p>
            </div>
            <div class="level-end">
            
                <div class="field has-addons is-flex-center-mobile has-mt-5-mobile is-flex-wrap is-flex-middle">
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" rel="noopener" title="Creative Commons" href="https://creativecommons.org/">
                        
                        <i class="fab fa-creative-commons"></i>
                        
                    </a>
                </p>
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" rel="noopener" title="Attribution 4.0 International" href="https://creativecommons.org/licenses/by/4.0/">
                        
                        <i class="fab fa-creative-commons-by"></i>
                        
                    </a>
                </p>
                
                </div>
            
            </div>
        </div>
    </div>
</footer>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script>
<script>moment.locale("zh-Hans");</script>


<script>
var IcarusThemeSettings = {
    site: {
        url: 'https://ayang818.gitee.io/blog',
        external_link: {"enable":true,"exclude":[]}
    },
    article: {
        highlight: {
            clipboard: true,
            fold: 'unfolded'
        }
    }
};
</script>


<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer></script>





<script src="/blog/js/animation.js"></script>



<script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer></script>
<script src="/blog/js/gallery.js" defer></script>



<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update
            my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        });
    });
</script>


<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    MathJax.Hub.Config({
        'HTML-CSS': {
            matchFontHeight: false
        },
        SVG: {
            matchFontHeight: false
        },
        CommonHTML: {
            matchFontHeight: false
        },
        tex2jax: {
            inlineMath: [
                ['$','$'],
                ['\\(','\\)']
            ]
        }
    });
});
</script>


<a id="back-to-top" title="回到顶端" href="javascript:;">
    <i class="fas fa-chevron-up"></i>
</a>
<script src="/blog/js/back-to-top.js" defer></script>














<script src="/blog/js/main.js" defer></script>

    
    <div class="searchbox ins-search">
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="想要查找什么..." />
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: '文章',
                PAGES: '页面',
                CATEGORIES: '分类',
                TAGS: '标签',
                UNTITLED: '(无标题)',
            },
            CONTENT_URL: '/blog/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/blog/js/insight.js" defer></script>
<link rel="stylesheet" href="/blog/css/search.css">
<link rel="stylesheet" href="/blog/css/insight.css">
    
<script src="/blog/node_modules/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"node_modules/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/blog/node_modules/assets/shizuku.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body>
</html>